-
Notifications
You must be signed in to change notification settings - Fork 481
New article on extending widgets with the widget factory. #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ping @jzaefferer and @scottgonzalez. If you guys have some time I would appreciate a read through of this. This is the first part of implementing jquery/api.jqueryui.com#20. |
|
||
### Creating Widget Extensions | ||
|
||
Creating widgets with the widget factory is done by passing the name of the widget and a prototype object to `$.widget`. The following creats a "myWidget" widget in the "myNamespace" namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"creats" -> "creates"
When talking about widget extensions we should also mention the lack of polymorphism on the plugin bridge. While you can extend dialog with a superDialog, you can't call dialog methods through the superDialog bridge. Once you have access to the instance itself, it'll work fine. |
@jzaefferer To make sure I understand, this is what you're referring to correct?
|
Yep, exactly. |
Thanks @jzaefferer. Updates made 878403c. |
|
||
### Creating Widget Extensions | ||
|
||
Creating widgets with the widget factory is done by passing the name of the widget and a prototype object to `$.widget`. The following creates a "myWidget" widget in the "myNamespace" namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$.widget
-> $.widget()
We should probably build on top of the existing widget factory docs. Perhaps use |
|
||
Here superDialog and dialog are essentially equivalent widgets with different names and namepaces. To make our new widget more interesting we can add methods to its prototype. | ||
|
||
The prototype object to use for a widget is the final argument passed to `$.widget`. To this point our examples have been using an empty object. Let's add a method to the prototype: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$.widget
-> $.widget()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"To this point" -> "Up to this point" or "So far"
We should add a section about extending a widget instance for one-off customizations. |
@scottgonzalez I addressed all of your comments other than:
I started down this route and it became a little messy. These are progressbar's methods:
I had trouble building good examples based off these methods because they're ones I don't think people generally use... and I really can't see anyone wanting to override them. I think using dialog's I did change the namespace to Feel free to ping me about this. |
|
||
When we place methods on the prototype object, we are not actually overriding the original method - rather, we are placing a new method at a higher level in the prototype chain. | ||
|
||
To make the parent's methods available, the widget factory provides two methods - `_super()` and `superApply()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_superApply()
|
||
### Using `_super()` and `_superApply()` to Access Parents | ||
|
||
The [`_super()`](http://api.jqueryui.com/jquery.widget/#method-_super) and [`_superApply()`](http://api.jqueryui.com/jquery.widget/#method-_superApply) are methods that access methods of the same same in the parent widget. Refer to the following example. Like the previous one, this example also overrides the `open()` method to log `"open"`. However, this time `_super()` is run to invoke dialog's `open()` and open the dialog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either drop "The" or change to something like "The _super() and _superApply() methods access methods..."
Just a few minor tweaks needed and that one sentence that I find really confusing. |
Landed in 4cf8c56. |
No description provided.